using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UnityEngine;

public static class Tools
{
    public static void Run(string path)
    {
        Process.Start(path);
    }

    public static void Run(string path, string arguments)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo
        {
            FileName = path,
            Arguments = arguments,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = true,
            StandardOutputEncoding = Encoding.GetEncoding("GB2312"),
        };

        Process process = new Process{ StartInfo = startInfo };
        process.Start();

        // 读取输出和错误信息
        string standardOutput = process.StandardOutput.ReadToEnd();
        string standardError = process.StandardError.ReadToEnd();

        process.WaitForExit(); // 确保命令完全执行完成

        // 记录输出和错误
        if (!string.IsNullOrEmpty(standardOutput))
        {
            UnityEngine.Debug.Log("<color=green>" + standardOutput + "</color>");
        }
        if (!string.IsNullOrEmpty(standardError))
        {
            UnityEngine.Debug.Log("<color=red>" + standardError + "</color>");
        }
    }
}
